package com.bupt.liutong.admin.shop.bo;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.transaction.annotation.Transactional;

import com.bupt.liutong.admin.core.base.BaseBo;
import com.bupt.liutong.admin.shop.dao.AttrValDao;
import com.bupt.liutong.admin.shop.dto.AttrVal;
import com.bupt.liutong.admin.shop.form.AttrValForm;
import com.bupt.liutong.util.BeanUtils;

public class AttrValBo extends BaseBo {

	private AttrValDao attrValDao;

	public List<AttrValForm> getAttrValsByPage(AttrValForm attrValForm,
			HttpServletRequest request) {
		AttrVal attrVal = new AttrVal();
		sm.pagingWithNoCriteria(attrValForm, attrVal, "shop_attr_val.getAttrValsCount");
		List<AttrVal> attrVals = attrValDao.getAttrValsByPage(attrVal);
		return BeanUtils.dtoToForm(attrVals, AttrValForm.class);
	}

	public AttrValForm getAttrValById(AttrValForm attrValForm) {
		AttrValForm resultForm = new AttrValForm();
		AttrVal attrVal = attrValDao.getAttrValById(attrValForm.getId());
		BeanUtils.copyProperties(resultForm, attrVal);
		return resultForm;
	}

	@Transactional
	public void insertAttrVal(AttrValForm attrValForm) {
		AttrVal attrVal = new AttrVal();
		BeanUtils.copyProperties(attrVal, attrValForm);
		attrValDao.insertAttrVal(attrVal);
	}

	@Transactional
	public void updateAttrVal(AttrValForm attrValForm) {
		AttrVal attrVal = new AttrVal();
		BeanUtils.copyProperties(attrVal, attrValForm);
		attrValDao.updateAttrVal(attrVal);
	}

	@Transactional
	public void deleteAttrVals(String[] ids) {
		if (ids != null) {
			for (int i = 0; i < ids.length; i++) {
				attrValDao.deleteAttrVal(Integer.parseInt(ids[i]));
			}
		}
	}

	public void setAttrValDao(AttrValDao attrValDao) {
		this.attrValDao = attrValDao;
	}
}
